package com.itboye.mengwu.data.repository;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.utils.BaseErrorListener;
import com.itboye.core.utils.BaseSuccessReqListener;
import com.itboye.core.utils.ByJsonRequest.Builder;
import com.itboye.mengwu.data.interfaces.IWxPay;
import com.itboye.mengwu.data.model.OrderBean;
import com.itboye.mengwu.data.model.PersonDataBean;
import com.itboye.mengwu.data.model.WePayModel;

/***
 * 微信相关
 * 
 * @author admin
 * 
 */
public class WxPayRepository extends BaseNetRepository implements
		IWxPay<WePayModel> {
	public static final String WxPay = "BY_WxpayApp_preOrder";// 8.2 微信预支付
	public static final String WxLogin = "BY_Weixin_login";// 2.8 微信登陆
	public static final String WxBind = "BY_Weixin_bind";// 2.11 微信绑定
	
	String api = "100";

	public WxPayRepository(ICompleteListener iCompleteListener) {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(WePayModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(WePayModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(WePayModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getInfo(WePayModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<WePayModel> queryYouHuiQuan(WePayModel model) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 2.11 微信绑定
	 * 
	 */
	@Override
	public void bindWx(String code, String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", code);
		params.put("uid", uid);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(WxLogin, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 2.8 微信登陆
	 */
	@Override
	public void loginByWx(String code) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<PersonDataBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", code);
		(new Builder<PersonDataBean>())
				.setTypeVerParamsAndReturnClass(WxLogin, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<PersonDataBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/***
	 * 10.2 微信预支付
	 */
	@Override
	public void wxPay(String code, String totalPrice, String desc) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<WePayModel>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", code);
		// params.put("total_price", totalPrice);
		// params.put("desc", desc);
		(new Builder<WePayModel>())
				.setTypeVerParamsAndReturnClass(WxPay, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<WePayModel>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void buyInstant(String uid, String pid, String count, String pskuId,
			String redId, String couponId, String money, String note,
			String addressId, String form) {
		// TODO Auto-generated method stub
		
	}

}
